﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QL_Nha_Sach_Phuong_Nam
{
    public partial class FormPhanQuyen : Form
    {
        CXulyRole XulyRole;
        List<Quyen> dsQuyen;

        public List<Quyen> DsQuyen
        {
            get { return dsQuyen; }
            set { dsQuyen = value; }
        }
        public FormPhanQuyen()
        {
            InitializeComponent();
        }

        private void FormPhanQuyen_Load(object sender, EventArgs e)
        {
            XulyRole = new CXulyRole();
            #region Load dữ liệu quyền lên list chọn
            foreach (Quyen q in XulyRole.GetListQuyen())
            {
                ListViewItem lvi = lstchuachon.Items.Add(q.QuyenID.ToString());
                lvi.SubItems.Add(q.QuyenNo);
                lvi.SubItems.Add(q.QuyenDescription);
            }
            #endregion
        }

        private void btnquaphai_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem lvi in lstchuachon.SelectedItems)
            {
                ListViewItem lvichon = lstdachon.Items.Add(lvi.SubItems[0].Text);
                lvichon.SubItems.Add(lvi.SubItems[1].Text);
                lvi.SubItems.Add(lvi.SubItems[2].Text);
            }
        }

        private void btnquatrai_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem lvi in lstdachon.SelectedItems)
            {
                lstdachon.Items.Remove(lvi);
            }
        }

        private void btnchon_Click(object sender, EventArgs e)
        {
            if (lstdachon.Items.Count == 0)
            {
                MessageBox.Show("Bạn vẫn chưa chọn quyền!!!");
                return;
            }

            foreach (ListViewItem lvi in lstdachon.SelectedItems)
            {
                Quyen q = new Quyen();
                q.QuyenID = int.Parse(lvi.SubItems[0].Text);
                q.QuyenNo = lvi.SubItems[1].Text;
                q.QuyenDescription = lvi.SubItems[2].Text;
                dsQuyen.Add(q);
            }
            Close();
        }

        private void btnhuychon_Click(object sender, EventArgs e)
        {
            Close();
        }

    }
}
